package S16.first;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.*;
import java.util.List;
import java.util.stream.Stream;

public class F01 {

	public static void main(String[] args) throws IOException {
//		byte[] bs = Files.readAllBytes(Paths.get("D:\\ldf\\java\\Books.txt"));
//		byte[] bs = Files.readAllBytes(Paths.get("D:/ldf", "java","Books.txt"));
		Path path = Paths.get("./src/S16/first/Hello.txt");
		System.out.println("(1)使用readAllBytes()返回字节数组");
		byte[] bs = Files.readAllBytes(path);
//		String s = new String(bs,"GBK");  //Charset.defaultCharset()
		String s = new String(bs,Charset.forName("GBK"));
		System.out.println(s);
		
		System.out.println("(2)使用readAllLines()返回List:");
		List<String> lines = Files.readAllLines(path, Charset.forName("GBK"));
		lines.forEach(System.out::println);

		System.out.println("(3)使用lines()方法返回Stream");
		Stream<String> stream = Files.lines(path, Charset.forName("GBK"));
		stream.forEach(System.out::println);
	}

}
